package com.jlz.actions.console.column;

import org.apache.struts2.convention.annotation.Standard;
import org.springframework.beans.factory.annotation.Autowired;

import com.jlz.beans.core.CategoryBean;
import com.jlz.beans.core.CategoryTable;
import com.jlz.beans.def.ColumnBean;
import com.julewa.Client;
import com.julewa.db.BeanValidator;

@Standard(rest="column.ID")
public class SaveAction {
	private @Autowired ColumnBean column;
	private @Autowired BeanValidator validator;
	private @Autowired Client client;
	public String execute(){
		if(!validator.checkColumns("column", column)){
			return "edit";
		}
		CategoryBean cate = column.getCategory();
		CategoryTable table = cate.getTableOf(column.getType());
		if(column.getID() == null){
			//to create column 
			table.appendColumn(column);
			client.putMessage("成功新增字段");
		}else{
			table.updateColumn(column);
			client.putMessage("成功修改字段");
		}
		return "edit";
	}

	public ColumnBean getColumn() {
		return column;
	}

	public void setColumn(ColumnBean column) {
		this.column = column;
	}
	
}
